﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Email.Subscription;
using SqlOperate;

public partial class Member_Subscription_SubscriptionProductList : Base.BasePage
{
    public string pageStr = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (CheckCookies())
            {
                if (!IsPostBack)
                {
                    Bind();
                }
            }
            else
                Response.Redirect("../../login/login.aspx");

        }
    }
    private void Bind()
    {
        int userid = int.Parse(GetCookie("UserID"));
        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx";
        PageNo1.Strurl = strURl;
        PageNo1.FldName = "AddDate";
        PageNo1.Table = "U_SubscriptionProduct as a inner join U_UserInfo b on a.UserID=b.UserID and b.UserID="+userid;
        PageNo1.StrGetFields = "a.ID,a.UserID,a.Type,a.Keyword,a.IndType,a.Area,AddDate,a.Validity";
        PageNo1.PageSize = 5;
        if (Request.QueryString["page"] != "" && Request.QueryString["page"] != null)
        {
            PageNo1.Pageindex = Convert.ToInt32(Request.QueryString["page"].ToString());
            if (Session["strWhere"] != null)
            {
                PageNo1.Where= Session["strWhere"].ToString();
            }
            else
            {
                PageNo1.Where = "1=1";
            }
            DataTable dt = PageNo1.BindViewDesc();
            if (dt.DefaultView.Count == 0)
            {
                lblMessage.Visible = true;
                lblMessage.Text = "暂无数据信息";
            }
            else {
                lblMessage.Visible = false;
            }
            dlstSubscription.DataSource = dt.DefaultView;
            dlstSubscription.DataBind();
        }
        else {
            Session["strWhere"] = "1=1";
            PageNo1.Where = "1=1";
            PageNo1.Pageindex = 1;
            DataTable dt = PageNo1.BindViewDesc();
            if (dt.DefaultView.Count == 0)
            {
                lblMessage.Visible = true;
                lblMessage.Text = "暂无数据信息";
            }
            else
            {
                lblMessage.Visible = false;
            }
            dlstSubscription.DataSource = dt.DefaultView;
            dlstSubscription.DataBind();
        }
    }
    protected void BtnDelete(object sender, CommandEventArgs e)
    {
        int ID = int.Parse(e.CommandArgument.ToString());
        string sql = "delete from U_SubscriptionProduct where ID=" + ID + "";
        SqlHelper.ExecuteNonQuery(sql);
        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx?page=1";
        Response.Redirect(strURl);
        Response.End();
    }
}
